<table class="easyui-datagrid" id="fileList" data-options="url:'grant/files',fit:true,singleSelect:true,
	fitColumns:true,rownumbers:true,pagination:true,pageSize:20,pageList:[20,50,100,200,500,1000]">
	<thead>
        <tr>
            <th data-options="field:'title',width:$(this).width() * 0.55,align:'center',formatter:showDownloadTitle">标题</th>
            <th data-options="field:'personCount',width:$(this).width() * 0.1,align:'center'">人数</th>
            <th data-options="field:'teacherName',width:$(this).width() * 0.1,align:'center'">发放人</th>
            <th data-options="field:'money',width:$(this).width() * 0.1,align:'center'">总金额</th>
            <th data-options="field:'grantTime',width:$(this).width() * 0.15,align:'center'">发放时间</th>
            <th data-options="field:'title2',width:$(this).width() * 0.05,align:'center',formatter:showDownloadBtn">操作</th>
        </tr>
    </thead>
</table>

<script>
var showDownloadTitle = function(value,row,index) {
	return '<a href="grant/download?id=' + row.id + '" style="color:blue;" >' + value + '</a>';
}
var showDownloadBtn = function(value,row,index) {
	return '<a href="grant/download?id=' + row.id + '" style="color:blue;">下载</a>&nbsp;'
		+ '<a href="javascript:void(0)" style="color:blue;" onclick="revocation(\'' + row.id + '\')" >撤销</a>';
}
var revocation = function(id) {
	$.messager.prompt('提示','请输入管理密码！',function(r) {
		if(r) {
			$.ajax({
				url:'user/info?v=' + new Date(),
				success:function(info) {
					if(info.userType == 2 && info.user.managePwd == r) {
						doVocation(id);return;
					}

					$.messager.alert('提示','您输入的密码有误！');
				}
			});
		}
	});
}

var doVocation = function(id) {
	$.ajax({
		url:'grant/revocation?id=' + id,
		success:function(result){
			if(result.errorInfo != 'none') {
				$.messager.alert('提示',result.errorInfo);
				return;
			} 
			$('#fileList').datagrid('reload');
			$.messager.alert('提示','撤销成功！');
		}
	});
}
</script>